import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import {Level, ClientData} from "../../../model/pages/client/holder-client-detail/holder-client-detail.model";
import {Observable} from "rxjs/Observable";

@Injectable()
export class HolderClientDetailProvider {
    //private coreUrl='/customer/detail/';
    private coreUrl='/party/v1/detail/';

    // 用户等级
    private level=Level;

    constructor(public http: HttpClient) {

    }

    // 获取客户详情数据 type 1核心客户；2：准客户
    getClientDetailData(clientNum):Observable<any>{
         return this.http.get(this.coreUrl+clientNum);

    }


    /**
     * 获取客户头像
     * @param {ClientModel} client
     * @returns {string}
     */
    public static getClientAvatar(client: any): string {
        if (!client) return './assets/images/clients/ico_portrait.png';
        //if (client.avatar) return client.avatar;

        const gender = client.sex;
        /*if (gender === 'M') {
            return './assets/images/client/client-detail/icon_man_s.png';
        } else if (gender === "F") {
            return './assets/images/client/client-detail/icon_woman_s.png';
        } else {
            return './assets/images/client/client-detail/icon_unknown_s.png';
        }*/
        if (gender === 'M') {
            return './assets/images/client/client-detail/icon_man.png';
        } else if (gender === "F") {
            return './assets/images/client/client-detail/icon_woman.png';
        } else {
            return './assets/images/client/client-detail/icon_unkonw.png';
        }
    }

    // 客户等级分级返回图标样式
    public getClientLevel(str){
        const code=String(str);
        let status=true;
        for(let key in this.level){
            if(this.level[key]==str){
                status=false;
                return String(key);
            }
        }
        if(status){
            return '';
        }
    }
}
